import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:oral_cloud/model/patient.dart';
import 'package:oral_cloud/ui/page/image/medical_image_page.dart';
import 'package:oral_cloud/ui/page/login/login_page.dart';
import 'package:oral_cloud/ui/page/login/modify_password_page.dart';
import 'package:oral_cloud/ui/page/login/person_page.dart';
import 'package:oral_cloud/ui/page/patient/patient_details_page.dart';
import 'package:oral_cloud/ui/page/patient/patient_list_page.dart';

import 'package:oral_cloud/ui/page/splash.dart';
import 'package:oral_cloud/ui/widget/page_route_anim.dart';

class RouteName {
  static const String splash = 'splash';
  static const String login = 'login';
  static const String home = 'home';
  static const String modify_password = 'modify_password';
  static const String patient_details = 'patient_details';
  static const String person = 'person';
  static const String medical_image = 'medical_image';
}

class Router {
  static GlobalKey<NavigatorState> navigatorState=GlobalKey();
  static Route<dynamic> generateRoute(RouteSettings settings) {
    switch (settings.name) {
      case RouteName.splash:
        return NoAnimRouteBuilder(SplashPage());
      case RouteName.login:
        return NoAnimRouteBuilder(LoginPage());
      case RouteName.modify_password:
        return CupertinoPageRoute(builder: (_) =>ModifyPasswordPage());
      case RouteName.home:
        return NoAnimRouteBuilder(PatientListPage());
      case RouteName.patient_details:
        var patient = settings.arguments as Patient;
        return CupertinoPageRoute(builder: (_) => PatientDetailsPage(patient));
      case RouteName.person:
        return CupertinoPageRoute(builder: (_) => PersonPage());
      case RouteName.medical_image:
        var images = settings.arguments as List;
        return CupertinoPageRoute(builder: (_) => MedicalImagePreview(images: images,index:0,));
      default:
        return CupertinoPageRoute(
            builder: (_) => Scaffold(
                  body: Center(
                    child: Text('No route defined for ${settings.name}'),
                  ),
                ));
    }
  }
}


class FadeRoute extends PageRouteBuilder {
  final Widget page;
  FadeRoute({this.page}): super(
    pageBuilder: (
        BuildContext context,
        Animation<double> animation,
        Animation<double> secondaryAnimation,
        ) =>page,transitionsBuilder: (
      BuildContext context,
      Animation<double> animation,
      Animation<double> secondaryAnimation,
      Widget child,
      ) =>FadeTransition(
    opacity: animation,
    child: child,
  ),
  );
}

/// Pop路由
class PopRoute extends PopupRoute {
  final Duration _duration = Duration(milliseconds: 300);
  Widget child;

  PopRoute({@required this.child});

  @override
  Color get barrierColor => null;

  @override
  bool get barrierDismissible => true;

  @override
  String get barrierLabel => null;

  @override
  Widget buildPage(BuildContext context, Animation<double> animation,
      Animation<double> secondaryAnimation) {
    return child;
  }

  @override
  Duration get transitionDuration => _duration;
}
